<?php
if ( !isGod() )
	if ( !getRights($mod,'view') )
	{
		showMsg('Không có quyền truy cập vào trang này !','error','center');
		die();
	}

$sql = "SELECT um_USER. * , um_GROUP. * FROM um_USER, um_GROUP WHERE um_USER.GNO = um_GROUP.GID AND god=0 AND um_USER.USERNAME NOT IN ('" . $_SESSION['sesusername'] . "') ORDER BY gid ASC";

$rs = $link->execute($sql);

//luu cac gid
$strGroupID = "";

?>
<form name="frmList" method="POST" action="admin.php?mod=UManager&delete_user.php">
<?php
	$prevGroup = "";
	
	echo '<table cellspacing="0" cellpadding="0" border="0" align="center" width="98%">';

	echo '<tr>';
	echo '<td colspan="3" align="right">';
	echo '<a href="admin.php?mod=UManager&act=add_group" style="text-decoration: none; color: #000066; font-weight: bold"><img src="images/add_trans.gif" align="absmiddle" border="0" alt="Thêm nhóm mới" style="cursor: hand">&nbsp;Thêm nhóm người dùng&nbsp;</a>';
	echo '</td>';
	echo '</tr>';			

	echo '<tr>';
	echo '<td colspan="3" align="right">&nbsp;</td>';
	echo '</tr>';			
	
	$stt = 0;
	
	while ( !$rs->EOF )
	{
		if ( ++$stt % 2 == 0 )	$clr = "#F0F0F0";
		else	$clr = "#FFFFCC";
	
		if ( $rs->fields('gid') != $prevGroup )
		{
			$strGroupID = $strGroupID . $rs->fields('gid') . ",";		
			//in large topic
			echo '<tr>';
			echo '<td align="center" height="25" width="21" bgcolor="#6699CC"><img id="img' . $rs->fields('gid') . '" src="images/plus.gif" border="0" align="absmiddle" style="cursor: hand" onClick="ToggleDiv(\'_' . $rs->fields('gid') . '_\',\'img' . $rs->fields('gid') . '\')"></td>';
			echo '<td bgcolor="#6699CC" class="clsTitle">&nbsp;<img src="images/groupuser.gif" border="0" align="absmiddle">&nbsp;Nhóm ' . $rs->fields('gname'); 
			echo '<td bgcolor="#6699CC" align="right">&nbsp;<a href="admin.php?mod=UManager&act=edit_group&gid=' . $rs->fields('gid') . '"><img src="images/edit.gif" border="0" alt="Hiệu chỉnh nhóm" style="cursor: hand"></a>&nbsp;<a href="javascript:vsConfirm(\'admin.php?mod=UManager&act=delete_group&gid=' . $rs->fields('gid') . '\',\'Ban co chac la muon xoa nhom ' . $rs->fields('gname') . ' hay khong ?\');"><img src="images/delete.gif" border="0" alt="Xóa nhóm" style="cursor: hand"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="admin.php?mod=UManager&act=gaccess&gid=' . $rs->fields('gid') . '"><img src="images/user_right.gif" border="0" align="absmiddle" alt="Phân quyền cho nhóm"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="admin.php?mod=UManager&act=add_user&gid=' . $rs->fields('gid') . '"><img src="images/user_add.gif" border="0" align="absmiddle" alt="Thêm người dùng vào nhóm"></a>&nbsp;&nbsp;</td>';
			echo '</tr>';
			
			echo '<tr>';
			echo '<td width="21">&nbsp;</td>';			
			echo '<td colspan="2">';
			
			echo '<table id="_' . $rs->fields('gid') . '_" cellpadding="0" cellspacing="1" border="0" width="100%" align="center" style="display: none; border: 1px solid #CCCCCC">';
			echo '<tr>';
			echo '<td width="20%" height="21" align="center" bgcolor="#AAAAAA" class="clsBold">Tên đăng nhập</td>';
			echo '<td width="30%" height="21" align="center" bgcolor="#AAAAAA" class="clsBold">Tên thật</td>';			
			echo '<td width="30%" height="21" align="center" bgcolor="#AAAAAA" class="clsBold">Địa chỉ Email</td>';
			echo '<td width="10%" height="21" align="center" bgcolor="#AAAAAA" class="clsBold" colspan="3">Thao tác</td>';			
			echo '</tr>';
			
			echo '<tr>';
			echo '<td height="20" bgcolor="' . $clr . '">&nbsp;' . $rs->fields('username') . '</td>';
			echo '<td bgcolor="' . $clr . '">&nbsp;' . $rs->fields('realname') . '</td>';			
			echo '<td bgcolor="' . $clr . '">&nbsp;' . $rs->fields('email') . '</td>';
			echo '<td align="center" bgcolor="' . $clr . '"><a href="admin.php?mod=UManager&act=swap_user&un=' . $rs->fields('username') . '&gid=' . $rs->fields('gid') . '"><img src="images/swap.gif" border="0" align="absmiddle" alt="Thay đổi nhóm người dùng" style="cursor: hand"></a></td>';			
			echo '<td align="center" bgcolor="' . $clr . '"><a href="admin.php?mod=UManager&act=edit_user&un=' . $rs->fields('username') . '"><img src="images/user_edit.gif" border="0" align="absmiddle" alt="Hiệu chỉnh" style="cursor: hand"></a></td>';			
			echo '<td align="center" bgcolor="' . $clr . '"><a href="javascript:vsConfirm(\'admin.php?mod=UManager&act=delete_user&un=' . $rs->fields('username') . '\',\'Ban co chac la muon xoa nguoi dung co ten dang nhap la ' . $rs->fields('username') . ' hay khong ?\');"><img src="images/user_del.gif" border="0" align="absmiddle" alt="Xóa" style="cursor: hand"></a></td>';						
			echo '</tr>';				
		}
		else
		{
			//minus
			echo '<tr>';
			echo '<td height="20" bgcolor="' . $clr . '">&nbsp;' . $rs->fields('username') . '</td>';
			echo '<td bgcolor="' . $clr . '">&nbsp;' . $rs->fields('realname') . '</td>';			
			echo '<td bgcolor="' . $clr . '">&nbsp;' . $rs->fields('email') . '</td>';
			echo '<td align="center" bgcolor="' . $clr . '"><a href="admin.php?mod=UManager&act=swap_user&un=' . $rs->fields('username') . '&gid=' . $rs->fields('gid') . '"><img src="images/swap.gif" border="0" align="absmiddle" alt="Thay đổi nhóm người dùng" style="cursor: hand"></a></td>';			
			echo '<td align="center" bgcolor="' . $clr . '"><a href="admin.php?mod=UManager&act=edit_user&un=' . $rs->fields('username') . '"><img src="images/user_edit.gif" border="0" align="absmiddle" alt="Hiệu chỉnh" style="cursor: hand"></a></td>';			
			echo '<td align="center" bgcolor="' . $clr . '"><a href="javascript:vsConfirm(\'admin.php?mod=UManager&act=delete_user&un=' . $rs->fields('username') . '\',\'Ban co chac la muon xoa nguoi dung co ten dang nhap la ' . $rs->fields('username') . ' hay khong ?\');"><img src="images/user_del.gif" border="0" align="absmiddle" alt="Xóa" style="cursor: hand"></a></td>';						
			echo '</tr>';							
		}
			
		$prevGroup = $rs->fields('gid');
		$rs->movenext();
		if ( $rs->fields('gid') != $prevGroup )
		{
			echo '<tr>';
			echo '<td colspan="6" align="right" bgcolor="#F5F5F5">&nbsp;</td>';
			echo '</tr>';
			echo '	</table>';
			echo '</td>';
			echo '</tr>';
			echo '<td><td colspan="3">&nbsp;</td></tr>';
		}
	}
	$rs->close();
	
	if ( $strGroupID != '' )
	{
		$strGroupID = substr($strGroupID,0,strlen($strGroupID)-1);
		//hien thi cac nhom chua cho user
		$sql = "SELECT * FROM um_group WHERE gid NOT IN(" . $strGroupID . ")";
	}
	else
		$sql = "SELECT * FROM um_group";
	$rs = $link->execute($sql);
	
	while ( !$rs->EOF )
	{
		echo '<tr>';
		echo '<td align="center" height="25" width="21" bgcolor="#6699CC"><img id="img' . $rs->fields('gid') . '" src="images/minus.gif" border="0" align="absmiddle"></td>';
		echo '<td bgcolor="#6699CC" class="clsTitle">&nbsp;<img src="images/groupuser.gif" border="0" align="absmiddle">&nbsp;Nhóm ' . $rs->fields('gname') . ' <font color="#FFFF00">[Chưa có người dùng]</font>'; 
		echo '<td bgcolor="#6699CC" align="right">&nbsp;<a href="admin.php?mod=UManager&act=edit_group&gid=' . $rs->fields('gid') . '"><img src="images/edit.gif" border="0" alt="Hiệu chỉnh nhóm" style="cursor: hand"></a>&nbsp;<a href="javascript:vsConfirm(\'admin.php?mod=UManager&act=delete_group&gid=' . $rs->fields('gid') . '\',\'Ban co chac la muon xoa nhom ' . $rs->fields('gname') . ' hay khong ?\');"><img src="images/delete.gif" border="0" alt="Xóa nhóm" style="cursor: hand"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="admin.php?mod=UManager&act=gaccess&gid=' . $rs->fields('gid') . '"><img src="images/user_right.gif" border="0" align="absmiddle" alt="Phân quyền cho nhóm"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="admin.php?mod=UManager&act=add_user&gid=' . $rs->fields('gid') . '"><img src="images/user_add.gif" border="0" align="absmiddle" alt="Thêm người dùng vào nhóm"></a>&nbsp;&nbsp;</td>';
		echo '</tr>';	
	
		$rs->movenext();
	}

	$rs->close();

	echo '</table>';
?>
</form>
